class AnswersController < ApplicationController

  def new
    @round_number = params["rn"]
    @round_number ||= 1
    
    flash.now[:notice] = "Question #{@round_number.to_i}"
    
    @answer = Answer.new

    @answer.question = Question.random #TODO: I wish I was in a model :(

  end
  
  
  def create
    @answer = Answer.new(params[:answer])

    if @answer.save
      round_number = params["rn"].to_i

      params["ia"] ||= '' # TODO: Am i needed?

      incorrect_answers = params["ia"].split('~')
      
      incorrect_answers << @answer.question_id unless @answer.correct?

      if round_number < 3
        redirect_to new_answer_path + "?rn=#{round_number + 1}" +
            "&ia=#{incorrect_answers.join('~')}"
      else
        redirect_to quiz_summary_path + "?rn=#{round_number}" +
        "&ia=#{incorrect_answers.join('~')}"
      end
    else
      render 'new'
    end
  end
  
  
end
